package com.example.huichaoliu;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.Window;
import android.view.View.OnClickListener;
import android.widget.ListView;
import android.widget.TextView;

import com.huichaoliu.adapters.ActivityShareAdapter;
import com.huichaoliu.app.R;
import com.huichaoliu.app.wxapi.WXEntryActivity;
import com.rederxu.farmer.BaseActivity;
import com.tencent.mm.sdk.modelbase.BaseReq;
import com.tencent.mm.sdk.modelbase.BaseResp;
import com.tencent.mm.sdk.modelmsg.SendAuth;
import com.tencent.mm.sdk.modelmsg.SendMessageToWX;
import com.tencent.mm.sdk.modelmsg.WXMediaMessage;
import com.tencent.mm.sdk.modelmsg.WXWebpageObject;
import com.tencent.mm.sdk.openapi.IWXAPI;
import com.tencent.mm.sdk.openapi.IWXAPIEventHandler;
import com.tencent.mm.sdk.openapi.WXAPIFactory;

public class ShareActivity extends BaseActivity implements OnClickListener {
	
	private IWXAPI wxApi = WXAPIFactory.createWXAPI(this, WXEntryActivity.APP_ID,false);
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.activity_share);
		super.onCreate(savedInstanceState);
	}
	
	@Override
	public void onClick(View v) {
		switch(v.getId()){
		case R.id.left_button:
			finish();
			break;
		case R.id.ic_share_wx:
//			WXWebpageObject webpage = new WXWebpageObject();
//			webpage.webpageUrl = "http://www.baidu.com/";
//			WXMediaMessage msg = new WXMediaMessage(webpage);
//		    msg.title = "这里填写标题";
//		    msg.description = "这里填写内容";
//		    //这里替换一张自己工程里的图片资源  
////		    Bitmap thumb = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);  
////		    msg.setThumbImage(thumb);
//		    SendMessageToWX.Req req = new SendMessageToWX.Req();
//		    req.transaction = String.valueOf(System.currentTimeMillis());
//		    req.message = msg;
////		    req.scene = 0 == 0 ? SendMessageToWX.Req.WXSceneSession:SendMessageToWX.Req.WXSceneTimeline; 
//		    req.scene = SendMessageToWX.Req.WXSceneTimeline;
//		    wxApi.sendReq(req);
		    
		    final SendAuth.Req req = new SendAuth.Req();
		    req.scope = "snsapi_userinfo";
		    req.state = "car";
		    boolean isSendReqOK = wxApi.sendReq(req);
		    Log.e("isSendReqOK", isSendReqOK + "");
			break;
		}
	}

	@Override
	public void init() {
		wxApi.registerApp(WXEntryActivity.APP_ID);
		((TextView) findViewById(R.id.title_text)).setText("分    享");
		findViewById(R.id.left_button).setOnClickListener(this);
		findViewById(R.id.ic_share_wx).setOnClickListener(this);
	}

	@Override
	public void initData() {
	}

	@Override
	public void onNetworkChanged(boolean isMobNetConnected,
			boolean isWifiConnected) {
		// TODO Auto-generated method stub

	}

}
